package top.zkh.login;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.java1234.dao.UserDao;
import com.java1234.model.User;
import com.java1234.util.DbUtil;

public class usermanageServlet extends HttpServlet{
	private DbUtil dbUtil = new DbUtil();
	private UserDao userdao=new UserDao();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		req.setCharacterEncoding ("utf-8");
		resp.setContentType("text/html;carset=utf-8");
		Connection con =null;
		PreparedStatement ps =null;	
		String id = (String)req.getSession().getAttribute("username");
		String name = req.getParameter("Name");
		String p = req.getParameter("password");
		String type = req.getParameter("sex");
		String price = req.getParameter("tele");
		User user = new User(id,p,name,type,price);
		try {
			con = dbUtil.getCon();
			int count=userdao.update(con, user);
			System.out.println(id);
			if(count==1)
			{
				System.out.println("添加成功");
				req.getRequestDispatcher("userfind.jsp").forward(req, resp);
			}else {
				System.out.println("添加失败");
				req.getRequestDispatcher("error.jsp").forward(req, resp);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doGet(req, resp);
	}

}